﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using easyList.Entities;

namespace easyList.IO.Reader
{
    class UNCPathLister
    {

        static UNCPathLister instance = null;
        static readonly object padlock = new object();

        UNCPathLister() { }
        public static UNCPathLister Instance
        {
            get
            {
                lock (padlock)
                {
                    if (instance == null)
                    {
                        instance = new UNCPathLister();
                    }
                    return instance;
                }
            }
        }


        public ArchiveObject listFiles(string path)
        {

            ArchiveObject folderContent = new ArchiveObject();

            if (path != "" && path != null)
            {
                
                string sourceID = Program.laststoreID;

                if (sourceID == "")
                {
                    sourceID = "notSpecified";
                }

                DirectoryInfo directoryInfo = new DirectoryInfo(path);
                FileInfo[] files = directoryInfo.GetFiles("*.*");

                foreach (FileInfo file in files)
                {
                    FileObject currentFile = new FileObject();
                    currentFile.filename = file.Name;
                    currentFile.storeID = sourceID;

                    currentFile.setSize(file.Length);
                    
                    // currentFile.extension = file.Extension;
                    folderContent.addFileObject(currentFile);
                }
            }

            return folderContent;
        }


        public ArchiveObject listFilesWithSubdirectories(string path)
        {
            ArchiveObject folderContent = new ArchiveObject();


            if (path != "" && path != null)
            {

                string sourceID = Program.laststoreID;

                if (sourceID == "")
                {
                    sourceID = "notSpecified";
                }

                DirectoryInfo directoryInfo = new DirectoryInfo(path);
                DirectoryInfo[] directories = directoryInfo.GetDirectories("*.*");

                //foreach (FileInfo file in files)
                //{
                //    FileObject currentFile = new FileObject();
                //    currentFile.filename = file.Name;
                //    currentFile.storeID = sourceID;

                //    currentFile.setSize(file.Length);

                //    // currentFile.extension = file.Extension;
                //    folderContent.addFileObject(currentFile);
                //}
            }

            return folderContent;
        }



    }
}
